home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / maths / mathsdlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  6.6 KB  |  246 lines

  1. // MathsDlg.cpp : implementation file
  2. //
  3.  
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1999 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. #include "stdafx.h"
  15. #include "Maths.h"
  16. #include "MathsDlg.h"
  17. #include "querydlg.h"
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CAboutDlg dialog used for App About
  27.  
  28. class CAboutDlg : public CDialog
  29. {
  30. public:
  31.     CAboutDlg();
  32.  
  33. // Dialog Data
  34.     //{{AFX_DATA(CAboutDlg)
  35.     enum { IDD = IDD_ABOUTBOX };
  36.     //}}AFX_DATA
  37.  
  38.     // ClassWizard generated virtual function overrides
  39.     //{{AFX_VIRTUAL(CAboutDlg)
  40.     protected:
  41.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  42.     //}}AFX_VIRTUAL
  43.  
  44. // Implementation
  45. protected:
  46.  
  47.     // Generated message map functions
  48.     //{{AFX_MSG(CAboutDlg)
  49.     virtual BOOL OnInitDialog();
  50.     //}}AFX_MSG
  51.     DECLARE_MESSAGE_MAP()
  52. };
  53.  
  54. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  55. {
  56.     //{{AFX_DATA_INIT(CAboutDlg)
  57.     //}}AFX_DATA_INIT
  58. }
  59.  
  60. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  61. {
  62.     CDialog::DoDataExchange(pDX);
  63.     //{{AFX_DATA_MAP(CAboutDlg)
  64.     //}}AFX_DATA_MAP
  65. }
  66.  
  67. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  68.     //{{AFX_MSG_MAP(CAboutDlg)
  69.         // No message handlers
  70.     //}}AFX_MSG_MAP
  71. END_MESSAGE_MAP()
  72.  
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CAboutDlg message handlers
  75.  
  76. BOOL CAboutDlg::OnInitDialog() 
  77. {
  78.     CDialog::OnInitDialog();
  79.     CenterWindow();    
  80.     return TRUE;  
  81. }
  82.  
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CMathsDlg dialog
  85.  
  86. CMathsDlg::CMathsDlg(CWnd* pParent /*=NULL*/)
  87.     : CDialog(CMathsDlg::IDD, pParent)
  88. {
  89.     //{{AFX_DATA_INIT(CMathsDlg)
  90.         // NOTE: the ClassWizard will add member initialization here
  91.     //}}AFX_DATA_INIT
  92.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  93.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  94. }
  95.  
  96. void CMathsDlg::DoDataExchange(CDataExchange* pDX)
  97. {
  98.     CDialog::DoDataExchange(pDX);
  99.     //{{AFX_DATA_MAP(CMathsDlg)
  100.     DDX_Control(pDX, IDC_OPPOSITE, m_ctlOpposite);
  101. //    DDX_Control(pDX, IDC_MATHSCTRL, m_ctlMaths);
  102.     //}}AFX_DATA_MAP
  103. }
  104.  
  105. BEGIN_MESSAGE_MAP(CMathsDlg, CDialog)
  106.     //{{AFX_MSG_MAP(CMathsDlg)
  107.     ON_WM_SYSCOMMAND()
  108.     ON_WM_PAINT()
  109.     ON_WM_QUERYDRAGICON()
  110.     ON_WM_LBUTTONDBLCLK()
  111.     ON_CONTROL(BN_CLICKED, IDC_OPPOSITE, OnOpposite)
  112.     //}}AFX_MSG_MAP
  113. END_MESSAGE_MAP()
  114.  
  115.  
  116. /////////////////////////////////////////////////////////////////////////////
  117. // CMathsDlg Event Map
  118.  
  119. BEGIN_EVENTSINK_MAP(CMathsDlg, CDialog)
  120.     ON_EVENT(CMathsDlg, IDC_MATHSCTRL, DISPID_CLICKIN, OnClickIn, VTS_XPOS_PIXELS VTS_YPOS_PIXELS)
  121.     ON_EVENT(CMathsDlg, IDC_MATHSCTRL, DISPID_CLICKOUT, OnClickOut, VTS_NONE)
  122. END_EVENTSINK_MAP()
  123.  
  124.  
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CMathsDlg message handlers
  127.  
  128. BOOL CMathsDlg::OnInitDialog()
  129. {
  130.     // Find out which control the user would like
  131.     CQueryDlg dlgQuery;
  132.     if (dlgQuery.DoModal() == TRUE)
  133.     {
  134.         m_ctlMaths.m_idControl = dlgQuery.GetChoice();
  135.     }
  136.     else
  137.         EndDialog(IDCANCEL);
  138.  
  139.     // Determine control rect by size of dialog
  140.     CRect rect;
  141.     GetWindowRect(&rect);
  142.     rect.top += 3 * (rect.Height() / 10);
  143.     rect.bottom -= 3 * (rect.Height() / 10);
  144.     rect.left += (rect.Width() / 10);
  145.     rect.right -= (rect.Width() / 10);
  146.     
  147.     m_ctlMaths.Create(NULL, WS_VISIBLE, rect, this, IDC_MATHSCTRL);
  148.     m_ctlMaths.ShowWindow(SW_SHOW);
  149.     m_ctlMaths.UpdateWindow();
  150.  
  151.     CDialog::OnInitDialog();
  152.  
  153.     // Set the icon for this dialog.  The framework does this automatically
  154.     //  when the application's main window is not a dialog
  155.     SetIcon(m_hIcon, TRUE);            // Set big icon
  156.     SetIcon(m_hIcon, FALSE);        // Set small icon
  157.  
  158.     // Set the Value of the Opposite Check Button based upon the value of
  159.     // the 'Opposite' property in the CMathsCtl OLE Control.
  160.     m_ctlOpposite.SetCheck(m_ctlMaths.GetOpposite());
  161.  
  162.     return TRUE;  // return TRUE  unless you set the focus to a control
  163. }
  164.  
  165. void CMathsDlg::OnSysCommand(UINT nID, LPARAM lParam)
  166. {
  167.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  168.     {
  169.         CAboutDlg dlgAbout;
  170.         dlgAbout.DoModal();
  171.     }
  172.     else
  173.     {
  174.         CDialog::OnSysCommand(nID, lParam);
  175.     }
  176. }
  177.  
  178. // If you add a minimize button to your dialog, you will need the code below
  179. //  to draw the icon.  For MFC applications using the document/view model,
  180. //  this is automatically done for you by the framework.
  181.  
  182. void CMathsDlg::OnPaint() 
  183. {
  184.     CDialog::OnPaint();
  185. }
  186.  
  187. // The system calls this to obtain the cursor to display while the user drags
  188. //  the minimized window.
  189. HCURSOR CMathsDlg::OnQueryDragIcon()
  190. {
  191.     return (HCURSOR) m_hIcon;
  192. }
  193.  
  194.  
  195. void CMathsDlg::OnLButtonDblClk(UINT, CPoint)
  196. {
  197.     // Here the Container handles the WM_LBUTTONDBLCLK message where it can
  198.     // do its own processing.  In this case, it sets the BackColor and
  199.     // ForeColor properties in the control.  This handler is only called 
  200.     // when double clicks occur OUTSIDE the control.  To handle double 
  201.     // clicks inside the control, have the control fire the stock DblClk
  202.     // event and then process it in the CMathsDlg EVENTSINK map.
  203.  
  204.     OLE_COLOR backClr = m_ctlMaths.GetBackColor();
  205.     OLE_COLOR foreClr = m_ctlMaths.GetForeColor();
  206.  
  207.     // Reverse the Colors!
  208.     m_ctlMaths.SetBackColor(foreClr);
  209.     m_ctlMaths.SetForeColor(backClr);
  210. }
  211.  
  212. /////////////////////////////////////////////////////////////////////////////
  213. // CMathsDlg Command Handlers
  214.  
  215. void CMathsDlg::OnOpposite()
  216. {
  217.     m_ctlMaths.SetOpposite((m_ctlOpposite.GetCheck() != 0));
  218. }
  219.  
  220.  
  221. /////////////////////////////////////////////////////////////////////////////
  222. // CMathsDlg Event Handlers
  223.  
  224. // These handlers are called when the user clicks with the mouse inside and
  225. // outside the 'face' on the CMathsCtl OLE Control.
  226.  
  227. BOOL CMathsDlg::OnClickIn(OLE_XPOS_PIXELS, OLE_YPOS_PIXELS)
  228. {
  229.     OLE_COLOR backClr = m_ctlMaths.GetBackColor();
  230.     OLE_COLOR foreClr = m_ctlMaths.GetForeColor();
  231.  
  232.     // Reverse the Colors!
  233.     m_ctlMaths.SetBackColor(foreClr);
  234.     m_ctlMaths.SetForeColor(backClr);
  235.  
  236.     return TRUE;    // We handled the event.  No need for futher processing
  237. }
  238.  
  239. BOOL CMathsDlg::OnClickOut()
  240. {
  241.     CButton* pCheck = (CButton*)GetDlgItem(IDC_OPPOSITE);
  242.     pCheck->SetCheck(pCheck->GetCheck() ? 0 : 1);
  243.     m_ctlMaths.SetOpposite((m_ctlOpposite.GetCheck() != 0));
  244.     return TRUE;    // We handled the event.  No need for futher processing
  245. }
  246.